/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VocSymbTest2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 *
 * @author StiggieBig
 */
public class GrammarRuleSet<T extends GrammarRule> implements Iterable<T>{

    SortedSet<T> grammarRuleSet;
    ArrayList<T> grammarRuleList;
    
    public GrammarRuleSet() {
        grammarRuleSet = new TreeSet<T>(new GrammarRuleComparator<T>());
        grammarRuleList = new ArrayList<>();
    }

    public GrammarRuleSet(T newGrammarRule) {
        grammarRuleSet = new TreeSet<T>(new GrammarRuleComparator<T>());
        grammarRuleSet.add(newGrammarRule);
        grammarRuleList = new ArrayList<>();
        grammarRuleList.add(newGrammarRule);
    }

    public GrammarRuleSet(GrammarRuleSet<T> copyFrom) {
        grammarRuleSet = new TreeSet<T>(new GrammarRuleComparator<T>());
        for (T tempGrammarRule : copyFrom) {
            grammarRuleSet.add(tempGrammarRule);
        }
        for (T tempGrammarRule : copyFrom) {
            grammarRuleList.add(tempGrammarRule);
        }
    }
    
    public void add(T newGrammarRule){
    	grammarRuleSet.add(newGrammarRule);
        grammarRuleList.add(newGrammarRule);
    }

    public int GetGrammarRuleIndex(T grammarRule){
        int indexOfGramRuleToFind = -1;
        grammarRuleList.indexOf(grammarRule);
        return indexOfGramRuleToFind;
    }
    
    public GrammarRule GetGrammarRuleAtIndex(int index){
        GrammarRule grammarRuleToReturn = new GrammarRule();
        
        if(0 < index && index < grammarRuleList.size()){
            grammarRuleToReturn = new GrammarRule(grammarRuleList.get(index));
        }
        
        return grammarRuleToReturn;
    }
    
    void Print() {
    	for (Iterator<T> it = grammarRuleSet.iterator(); it.hasNext();) {
            T tempGrammarRule = it.next();
            tempGrammarRule.Print();
            if(it.hasNext()){
                System.out.print(", ");
            }
        }
    }

	@Override
	public Iterator<T> iterator() {
		// TODO Auto-generated method stub
		return grammarRuleSet.iterator();
	}
}

